package com.ttl.ittl.requirement;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.ttl.common.util.CommonUtils;

public class RequirementAction extends DispatchAction {
	
    public ActionForward bank(ActionMapping mapping, ActionForm form, 
    		HttpServletRequest request, HttpServletResponse response) throws Exception {
    	    	    	    	
    	String docNo = RequirementBO.getMaxDocNo("REQ");    	
    	String currentDate = CommonUtils.getCurrentDate();
    	
		String user 	 = (String)request.getSession().getAttribute("userName");
		System.out.println(CommonUtils.getDateTimeForStamp()+" #user:"+user+" #use :RequirementAction #mode :blank ");
		
    	request.getSession().setAttribute("docNo", docNo);
    	request.getSession().setAttribute("docDate", currentDate);
    	
	    return mapping.findForward("blank");
    }

    
    public ActionForward add(ActionMapping mapping, ActionForm form, 
    		HttpServletRequest request, HttpServletResponse response) throws Exception {

		String user 	 = (String)request.getSession().getAttribute("userName");
		System.out.println(CommonUtils.getDateTimeForStamp()+" #user:"+user+" #use :RequirementAction #mode :add ");
		
		RequirementBO bo = new RequirementBO();
		boolean status = bo.add(form, request, response);
		
		if (status==true) {
			System.out.println("#status complete!!");
			return mapping.findForward("add_success");    	
		}else {
			System.out.println("#status fails!!");
			return mapping.findForward("add_fail");
		}	    
    }
    
	@SuppressWarnings("unchecked")
	public ActionForward show(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) 
			throws Exception {

		String user 	 = (String)request.getSession().getAttribute("userName");
		System.out.println(CommonUtils.getDateTimeForStamp()+" #user:"+user+" #use :RequirementAction #mode :show ");
		
		RequirementBO bo = new RequirementBO();														
		ArrayList results = (ArrayList)bo.find();				
				
		request.getSession().setAttribute("reqData", results);		
		return mapping.findForward("show_success");
	}
}
